import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

// elementPlus按需自动引入的插件
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";

// 引入svg提供方法
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";

// 引入mock提供方法
import { viteMockServe } from "vite-plugin-mock";

import path from "path";

//elementPlus 按需引入
export default defineConfig(({ command }) => {
  return {
    plugins: [
      // elementPlus部分
      AutoImport({
        resolvers: [ElementPlusResolver()],
      }),
      Components({
        resolvers: [ElementPlusResolver()],
      }),
      // svg部分
      createSvgIconsPlugin({
        // Specify the icon folder to be cached
        iconDirs: [path.resolve(process.cwd(), "src/assets/icons")],
        // Specify symbolId format
        symbolId: "icon-[dir]-[name]",
      }),
      // mock部分
      viteMockServe({
        // default
        mockPath: "mock",
        enable: command === "serve", //是否能够使用mock接口
      }),
      vue(),
    ],
    resolve: {
      alias: {
        "@": path.resolve("./src"), // 相对路径别名配置，使用 @ 代替 src
      },
    },
    css: {
      preprocessorOptions: {
        scss: {
          javascriptEnabled: true,
          additionalData: '@import "./src/styles/variable.scss";',
        },
      },
    },
  };
});
